<template>
  <a-layout-sider
    :class="['sider', isDesktop() ? null : 'shadow', theme, fixSiderbar ? 'ant-fixed-sidemenu' : null]"
    width="208px"
    :collapsible="collapsible"
    v-model="collapsed"
    :trigger="null"
  >
    <logo />
    <template v-if="isPatientManagePage && patientInfo.dataId">
      <div style="margin: 0 10px -10px 10px;" v-if="!collapsed">
        <a-affix :style="{ backgroundColor: '#fff' }">
          <div class="patient-panel">
            <a-row type="flex" justify="space-around" align="middle" :style="{ marginBottom: '0.5em' }">
              <a-col :flex="1">
                <a-avatar :src="patientInfo.avatar" :size="42" />
              </a-col>
              <a-col :flex="3">
                <p class="patient-info">{{ patientInfo.patientName }}</p>
                <span class="patient-age"
                  >{{ patientInfo.age }}岁&nbsp;&nbsp;|&nbsp;&nbsp;{{ patientInfo.patientSexText }}</span
                >
              </a-col>
            </a-row>
            <a-row :style="{ marginBottom: '0.5em' }">
              <div style="float: left; width: 15%;">
                <img src="~@/assets/jiankang-2.png" alt="logo" width="20px" />
              </div>
              <div style="float: right; width: 80%">糖尿病类型：{{ patientInfo.patientDiabetisTypeText }}</div>
            </a-row>
            <a-row type="flex" justify="space-around" align="top" wrap="nowrap">
              <div style="float: left; width: 15%;">
                <img src="~@/assets/bingzhi-copy-2.png" alt="logo" width="20px" />
              </div>
              <div style="float: right; width: 80%">简要病史：{{ patientInfo.patientDesc }}</div>
            </a-row>
          </div>
          <!-- <a-timeline :style="{backgroundColor: '#fff'}">
            <br>
            <a-timeline-item>姓名：{{patientInfo.patientName}}</a-timeline-item>
            <a-timeline-item>性别：</a-timeline-item>
            <a-timeline-item>年龄：{{patientInfo.age}}</a-timeline-item>
            <a-timeline-item>糖尿病类型：{{patientInfo.patientDiabetisTypeText}}</a-timeline-item>
            <a-timeline-item>简要病史：{{patientInfo.patientDesc}}</a-timeline-item>
          </a-timeline> -->
        </a-affix>
      </div>
      <div v-else style="margin: 0 10px -10px 10px;">
        <div class="patient-panel">
          <a-row type="flex" justify="space-around" align="middle" :style="{ marginBottom: '0.5em' }">
            <a-col :flex="1">
              <a-avatar :src="patientInfo.avatar" :size="42" />
              <p class="patient-info-little">{{ patientInfo.patientName }}</p>
            </a-col>
          </a-row>
        </div>
      </div>
    </template>
    <s-menu
      :collapsed="collapsed"
      :menu="menus"
      :theme="theme"
      @select="onSelect"
      @updateMenuTitle="onUpdateMenuTitle"
      :mode="mode"
      :style="smenuStyle"
    >
    </s-menu>
  </a-layout-sider>
</template>

<script>
import ALayoutSider from 'ant-design-vue/es/layout/Sider'
import Logo from '../tools/Logo'
import SMenu from './index'
import { mixin, mixinDevice } from '@/utils/mixin.js'
import { postAction } from '@/api/manage'
import { getUrlKey } from '@/utils/util'
import { PAGE_MENU_TYPE } from '@/store/mutation-types'

export default {
  name: 'SideMenu',
  components: { ALayoutSider, Logo, SMenu },
  mixins: [mixin, mixinDevice],
  props: {
    mode: {
      type: String,
      required: false,
      default: 'inline'
    },
    theme: {
      type: String,
      required: false,
      default: 'dark'
    },
    collapsible: {
      type: Boolean,
      required: false,
      default: false
    },
    collapsed: {
      type: Boolean,
      required: false,
      default: false
    },
    menus: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      patientInfo: {}
    }
  },
  computed: {
    smenuStyle() {
      let style = { padding: '0' }
      if (this.fixSiderbar) {
        style['height'] = 'calc(100% - 59px)'
        style['overflow'] = 'auto'
        style['overflow-x'] = 'hidden'
      }
      if (this.isPatientManagePage) {
        style['margin-bottom'] = '0.5em'
      }
      return style
    },
    isPatientManagePage() {
      if (getUrlKey(PAGE_MENU_TYPE.ParamsField) == PAGE_MENU_TYPE.HealthManage && getUrlKey(PAGE_MENU_TYPE.PatientId)) {
        this.getPatientInfo()
        return true
      }
    }
  },
  methods: {
    onSelect(obj) {
      this.$emit('menuSelect', obj)
    },
    onUpdateMenuTitle(obj) {
      this.$emit('updateMenuTitle', obj)
    },
    getPatientInfo() {
      postAction('/100/12/1001202', { patientId: getUrlKey(PAGE_MENU_TYPE.PatientId) }).then(res => {
        if (res.success) {
          this.patientInfo = res.result[0]
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
/* update_begin author:sunjianlei date:20190509 for: 修改侧边导航栏滚动条的样式 */
.sider {
  @scrollBarSize: 10px;

  ul.ant-menu {
    /* 定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
    &::-webkit-scrollbar {
      width: @scrollBarSize;
      height: @scrollBarSize;
      background-color: transparent;
      display: none;
    }

    & .-o-scrollbar {
      display: none;
    }

    /* 兼容IE */
    -ms-overflow-style: none;
    -ms-scroll-chaining: chained;
    -ms-content-zooming: zoom;
    -ms-scroll-rails: none;
    -ms-content-zoom-limit-min: 100%;
    -ms-content-zoom-limit-max: 500%;
    -ms-scroll-snap-type: proximity;
    -ms-scroll-snap-points-x: snapList(100%, 200%, 300%, 400%, 500%);

    /* 定义滚动条轨道 */
    &::-webkit-scrollbar-track {
      background-color: transparent;
    }

    /* 定义滑块 */
    &::-webkit-scrollbar-thumb {
      border-radius: @scrollBarSize;
      background-color: #eee;
      box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.1);

      &:hover {
        background-color: #dddddd;
      }

      &:active {
        background-color: #bbbbbb;
      }
    }
  }

  /** 暗色系滚动条样式 */
  &.dark ul.ant-menu {
    &::-webkit-scrollbar-thumb {
      background-color: #666666;

      &:hover {
        background-color: #808080;
      }

      &:active {
        background-color: #999999;
      }
    }
  }
}

/* update_end author:sunjianlei date:20190509 for: 修改侧边导航栏滚动条的样式 */
</style>

<!-- update_begin author:sunjianlei date:20190530 for: 选中首页的时候不显示背景颜色 -->
<style lang="less">
.ant-menu.ant-menu-root {
  & > .ant-menu-item:first-child {
    background-color: transparent;

    & > a,
    & > a:hover {
      color: rgba(0, 0, 0, 0.65);
    }

    &.ant-menu-item-selected {
      & > a,
      & > a:hover {
        color: @primary-color;
      }
    }
  }

  &.ant-menu-dark > .ant-menu-item:first-child {
    & > a,
    & > a:hover {
      color: rgba(255, 255, 255, 0.65);
    }

    &.ant-menu-item-selected {
      & > a,
      & > a:hover {
        color: rgba(255, 255, 255, 1);
      }
    }
  }
}
</style>

<style lang="less" scoped>
.patient-panel {
  margin-top: 0.5em;
  margin-bottom: 1.5em;
  box-shadow: 2px 1px 4px 0px rgb(187, 187, 187);
  background-color: #fff;
  border-radius: 8px;
  padding: 5px 10px;
  .patient-info {
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 0.2em;
  }
  .patient-info-little {
    text-align: center;
    margin-top: 0.6em;
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 0.2em;
  }
  .patient-age {
    color: #999999;
  }
}
</style>
<!-- update_end author:sunjianlei date:20190530 for: 选中首页的时候不显示背景颜色 -->

